package LOGIN;

import mapper.impl.StudentMapperImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@WebServlet("/update")
public class update extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf-8");
        String no = req.getParameter("no");
        String name = req.getParameter("name");
        String sex  = req.getParameter("sex");
        String account = req.getParameter("account");
        String phone = req.getParameter("phone");
        String age = req.getParameter("age");

        if (no == null || no ==""){
            req.setAttribute("error","学号不能为空");
            req.getRequestDispatcher("/WEB-INF/error(Test).jsp").forward(req,resp);
            return;
        }

        StudentMapperImpl update = new StudentMapperImpl();
        boolean updateStu = update.updateStu(no, name, account, sex, phone, age);

        if (updateStu == false){
            req.setAttribute("error","您输入的学号："+no+"错误,请重新输入");

            req.getRequestDispatcher("/WEB-INF/error(Test).jsp").forward(req,resp);
            return;
        }
        req.setAttribute("error","修改成功");
        req.getRequestDispatcher("/WEB-INF/error(Test).jsp").forward(req,resp);
    }
}
